package com.wc.算法基础课.A第一讲基础算法.日期问题.日期计算;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2024/3/10 11:21
 * @description https://www.acwing.com/problem/content/3221/
 */
public class Main {
    static int[] m = new int[]{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int y = sc.nextInt();
        int d = sc.nextInt();
        if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0) m[2] = 29;
        else m[2] = 28;
        int mth = 1;
        int day = 1;
        int dayNum = 1;
        while (++dayNum <= d) {
            if (day < m[mth]) {
                day++;
            } else {
                day = 1;
                mth++;
            }
        }
        System.out.println(mth);
        System.out.println(day);
    }
}
